home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / Amiga / info.c < prev    next >
C/C++ Source or Header  |  1995-02-14  |  2KB  |  97 lines

  1. /* amiga/info.c
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: info.c,v 1.2 1995/02/14 16:51:22 espie Exp espie $
  6.  * $Log: info.c,v $
  7.  * Revision 1.2  1995/02/14  16:51:22  espie
  8.  * *** empty log message ***
  9.  *
  10.  * Revision 1.1  1995/01/13  13:31:35  espie
  11.  * Initial revision
  12.  *
  13.  */
  14.  
  15. #include <proto/exec.h>
  16.  
  17. #include "defs.h"
  18. #include "extern.h"
  19. #include "amiga/amiga.h"
  20.  
  21. ID("$Id: info.c,v 1.2 1995/02/14 16:51:22 espie Exp espie $")
  22.  
  23.  
  24. /***
  25.  ***
  26.  ***        Info window handling
  27.  ***
  28.  ***/
  29.  
  30. /* We chose the easy way: outputting everything in a console window
  31.  * on the fly. An interesting improvement would be to buffer everything
  32.  * and open the window with the right size afterwards
  33.  */
  34. struct handle
  35.    {
  36.    FILE *file;
  37.    int linecount;
  38.    int maxlength;
  39.    int currentlength;
  40.    };
  41.  
  42. #define H(h, field)  ( ((struct handle *)h)->field )
  43.  
  44. void *begin_info(char *title)
  45.    {
  46.    struct handle *new;
  47.    
  48.    char buffer[50];
  49.    
  50.    new = malloc(sizeof(struct handle));
  51.    if (!new)
  52.       return 0;
  53.    sprintf(buffer, "CON:////%s/auto/close/wait", title);
  54.    new->file=fopen(buffer, "w");
  55.    if (!new->file)
  56.       {
  57.       free(new);
  58.       return 0;
  59.       }
  60.    new->linecount = 0;
  61.    new->maxlength = 0;
  62.    new->currentlength = 0;
  63.    return new;
  64.    }
  65.  
  66. void infos(void *handle, char *s)
  67.    {
  68.    if (handle)
  69.       {
  70.       fprintf( H(handle,file), s);
  71.       H(handle, currentlength) += strlen(s);
  72.       }
  73.    }
  74.  
  75. void info(void *handle, char *line)
  76.    {
  77.    infos(handle, line);
  78.    if (handle)
  79.       {
  80.       fputc('\n', H(handle, file));
  81.       if ( H(handle, currentlength) > H(handle, maxlength) )
  82.          H(handle, maxlength) = H(handle, currentlength);
  83.       H(handle, linecount)++;
  84.       }
  85.    }
  86.  
  87. void end_info(void *handle)
  88.    {
  89.    if (handle)
  90.       {
  91.       
  92.       fclose(H(handle, file));
  93.       free(handle);
  94.       }
  95.    }
  96.  
  97.